package net.nshc.kwkim.mycalc.activity;

import java.io.*;
import java.util.*;

import net.nshc.kwkim.mycalc.*;
import net.nshc.kwkim.mycalc.buttonlistener.*;
import net.nshc.kwkim.mycalc.db.*;
import android.app.*;
import android.content.*;
import android.content.pm.*;
import android.location.*;
import android.os.*;
import android.speech.*;
import android.text.method.*;
import android.util.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;

public class MyCalcActivity extends Activity {

	public static boolean bLog = true, bCheckLoc, bSound, bLocation, bVoice;
	public boolean bExtend = false;
	
	private static final int REQUEST_CODE = 1234;
	public static int iSize;
	private int mSelect;

	private static DBOpenHelper openHelper;

	private Button Extend, Voice, Location;
	private ImageButton btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, 
	btnDot, btnClr, btnBack, btnEqual, btnBlockS, btnBlockE, 
	btnPlus, btnMinus, btnDivide, btnMultiply, btnSqrt, btnPow, btnComma, btnAbComma,
	btnTan, btnCos, btnSin, btnFactorial, btnCombination, btnLog, btnLn, btnAbs;
	
	private static String result, location;
	
	//	private Button EqualBtn = null;
	public SharedPreferences pref;
	
	private TextView edit;
	private EditText input;
	private Window win;
	private Dialog dialog;
	private ListView list;
	private LocationManager mLocMan;
	private Geocoder mCoder;
	private String mProvider;
	
	private ArrayAdapter<String> ad2 = null;
	private List<Address> addr;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		win = getWindow();
		win.requestFeature(Window.FEATURE_CUSTOM_TITLE);
		win.setContentView(R.layout.main);
		win.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitile);
		
		edit = (TextView)findViewById(R.id.display);
		
		input = (EditText)findViewById(R.id.input);
		Extend = (Button)findViewById(R.id.extend);
		Voice = (Button)findViewById(R.id.voice);
		Location = (Button)findViewById(R.id.locate);
		
		mLocMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
		mProvider = mLocMan.getBestProvider(new Criteria(), true);
		mCoder = new Geocoder(this);
		openHelper = new DBOpenHelper(this.getApplicationContext());
		//openHelper.close();
		openHelper.open();
		if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY, "MyCalcActivity_log = openHelper = "+openHelper);
		batchScreen();
		
		edit.setMovementMethod(ScrollingMovementMethod.getInstance());
		edit.setOverScrollMode(TextView.OVER_SCROLL_IF_CONTENT_SCROLLS);
		edit.invalidate();
		
		if(savedInstanceState == null){
			bExtend = false;
		}else{
			bExtend = savedInstanceState.getBoolean("bExtend");
			edit.setText(savedInstanceState.getString("display"));
			input.setText(savedInstanceState.getString("input"));
		}
	}

	public void onPause() {
		super.onPause();
		mLocMan.removeUpdates(mListener);
	}
	
	public void onResume(){
		super.onResume();
		mLocMan.requestLocationUpdates(mProvider, 3000, 10, mListener);
		batchScreen();
	}

	LocationListener mListener = new LocationListener() {
		public void onLocationChanged(Location location) {
			Double Latitude, Longitude;
			Latitude = location.getLatitude();
			Longitude = location.getLongitude();
			addr = null;
			//String sloc = String.format("위도:%f\n경도:%f", Latitude, Longitude);
			try{
				addr = mCoder.getFromLocation(Latitude, Longitude, 5);
			} catch (IOException e){
				return;
			}


			if(addr == null){
				return;
			}
			if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY, "LOCATION INFORMATION = Before Latitude = "+Latitude+", Longitude = "+Longitude);
			//mResult.setText(sloc);
			Latitude = (Latitude*1E6);
			Longitude = (Longitude*1E6);
			if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY, "LOCATION INFORMATION = After Latitude = "+Latitude+", Longitude = "+Longitude);
			String temp = addr.get(0).toString();
			String[] arTemp = temp.split("\""); 
			MyCalcActivity.location = arTemp[1];
			if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY,"Location_Address_log = 주소 : "+arTemp[1]);
		}

		public void onProviderDisabled(String provider) {
		}

		public void onProviderEnabled(String provider) {
		}

		public void onStatusChanged(String provider, int status, Bundle extras) {
			switch (status) {
			case LocationProvider.OUT_OF_SERVICE:
				break;
			case LocationProvider.TEMPORARILY_UNAVAILABLE:
				break;
			case LocationProvider.AVAILABLE:
				break;
			}
		}
	};

	private void buttonMatching() {
		btn0 = (ImageButton)findViewById(R.id.zerobtn);
		btn0.setOnClickListener(new NumberButtonClickListener(this));
		btn1 = (ImageButton)findViewById(R.id.ontbtn);
		btn1.setOnClickListener(new NumberButtonClickListener(this));
		btn2 = (ImageButton)findViewById(R.id.twobtn);
		btn2.setOnClickListener(new NumberButtonClickListener(this));
		btn3 = (ImageButton)findViewById(R.id.threebtn);
		btn3.setOnClickListener(new NumberButtonClickListener(this));
		btn4 = (ImageButton)findViewById(R.id.fourbtn);
		btn4.setOnClickListener(new NumberButtonClickListener(this));
		btn5 = (ImageButton)findViewById(R.id.fivebtn);
		btn5.setOnClickListener(new NumberButtonClickListener(this));
		btn6 = (ImageButton)findViewById(R.id.sixbtn);
		btn6.setOnClickListener(new NumberButtonClickListener(this));
		btn7 = (ImageButton)findViewById(R.id.sevenbtn);
		btn7.setOnClickListener(new NumberButtonClickListener(this));
		btn8 = (ImageButton)findViewById(R.id.eightbtn);
		btn8.setOnClickListener(new NumberButtonClickListener(this));
		btn9 = (ImageButton)findViewById(R.id.ninebtn);
		btn9.setOnClickListener(new NumberButtonClickListener(this));
		btnDot = (ImageButton)findViewById(R.id.dotbtn);
		btnDot.setOnClickListener(new PointButtonClickListener(this));
		btnClr = (ImageButton)findViewById(R.id.clearbtn);
		btnClr.setOnClickListener(new ClearButtonClickListener(this));
		btnBack = (ImageButton)findViewById(R.id.backspacebtn);
		btnBack.setOnClickListener(new BackButtonClickListener(this));
		btnEqual = (ImageButton)findViewById(R.id.equalbtn);
		btnEqual.setOnClickListener(new EqualSignButtonClickListener(this,bLocation));
		btnBlockS = (ImageButton)findViewById(R.id.blocksbtn);
		btnBlockS.setOnClickListener(new BracketButtonClickListener(this,1));
		btnBlockE = (ImageButton)findViewById(R.id.blockebtn);
		btnBlockE.setOnClickListener(new BracketButtonClickListener(this,0));
		btnPlus = (ImageButton)findViewById(R.id.plusbtn);
		btnPlus.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnMinus = (ImageButton)findViewById(R.id.minusbtn);
		btnMinus.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnDivide = (ImageButton)findViewById(R.id.dividebtn);
		btnDivide.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnMultiply = (ImageButton)findViewById(R.id.multiplybtn);
		btnMultiply.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnSqrt = (ImageButton)findViewById(R.id.rootbtn);
		btnSqrt.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnPow = (ImageButton)findViewById(R.id.adbtn);
		btnPow.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnAbComma = (ImageButton)findViewById(R.id.adcommabtn);
		btnAbComma.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnTan = (ImageButton)findViewById(R.id.tanbtn);
		btnTan.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnCos = (ImageButton)findViewById(R.id.cosbtn);
		btnCos.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnSin = (ImageButton)findViewById(R.id.sinbtn);
		btnSin.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnFactorial = (ImageButton)findViewById(R.id.factorialbtn);
		btnFactorial.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnCombination = (ImageButton)findViewById(R.id.combinationbtn);
		btnCombination.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnComma = (ImageButton)findViewById(R.id.commabtn);
		btnComma.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnLog = (ImageButton)findViewById(R.id.logbtn);
		btnLog.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnLn = (ImageButton)findViewById(R.id.lnbtn);
		btnLn.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		btnAbs = (ImageButton)findViewById(R.id.absbtn);
		btnAbs.setOnClickListener(new ArithmeticOperatorButtonClickListener(this));
		
		if(bSound){	
			btn0.setSoundEffectsEnabled(true);
			btn1.setSoundEffectsEnabled(true);
			btn2.setSoundEffectsEnabled(true);
			btn3.setSoundEffectsEnabled(true);
			btn4.setSoundEffectsEnabled(true);
			btn5 .setSoundEffectsEnabled(true);
			btn6 .setSoundEffectsEnabled(true);
			btn7 .setSoundEffectsEnabled(true);
			btn8 .setSoundEffectsEnabled(true);
			btn9.setSoundEffectsEnabled(true);
			btnDot.setSoundEffectsEnabled(true);
			btnClr.setSoundEffectsEnabled(true);
			btnBack.setSoundEffectsEnabled(true);
			btnEqual.setSoundEffectsEnabled(true);
			btnBlockS.setSoundEffectsEnabled(true);
			btnBlockE.setSoundEffectsEnabled(true);
			btnPlus.setSoundEffectsEnabled(true);
			btnMinus.setSoundEffectsEnabled(true);
			btnDivide.setSoundEffectsEnabled(true);
			btnSqrt.setSoundEffectsEnabled(true);
			btnPow.setSoundEffectsEnabled(true);
			btnAbComma.setSoundEffectsEnabled(true);
			btnTan .setSoundEffectsEnabled(true);
			btnSin .setSoundEffectsEnabled(true);
			btnFactorial.setSoundEffectsEnabled(true);
			btnCombination.setSoundEffectsEnabled(true);
			btnComma.setSoundEffectsEnabled(true);
			btnLog.setSoundEffectsEnabled(true);
			btnLn .setSoundEffectsEnabled(true);
			btnAbs.setSoundEffectsEnabled(true);
		} else {
			btn0.setSoundEffectsEnabled(false);
			btn1.setSoundEffectsEnabled(false);
			btn2.setSoundEffectsEnabled(false);
			btn3.setSoundEffectsEnabled(false);
			btn4.setSoundEffectsEnabled(false);
			btn5 .setSoundEffectsEnabled(false);
			btn6 .setSoundEffectsEnabled(false);
			btn7 .setSoundEffectsEnabled(false);
			btn8 .setSoundEffectsEnabled(false);
			btn9.setSoundEffectsEnabled(false);
			btnDot.setSoundEffectsEnabled(false);
			btnClr.setSoundEffectsEnabled(false);
			btnBack.setSoundEffectsEnabled(false);
			btnEqual.setSoundEffectsEnabled(false);
			btnBlockS.setSoundEffectsEnabled(false);
			btnBlockE.setSoundEffectsEnabled(false);
			btnPlus.setSoundEffectsEnabled(false);
			btnMinus.setSoundEffectsEnabled(false);
			btnDivide.setSoundEffectsEnabled(false);
			btnSqrt.setSoundEffectsEnabled(false);
			btnPow.setSoundEffectsEnabled(false);
			btnAbComma.setSoundEffectsEnabled(false);
			btnTan .setSoundEffectsEnabled(false);
			btnSin .setSoundEffectsEnabled(false);
			btnFactorial.setSoundEffectsEnabled(false);
			btnCombination.setSoundEffectsEnabled(false);
			btnComma.setSoundEffectsEnabled(false);
			btnLog.setSoundEffectsEnabled(false);
			btnLn .setSoundEffectsEnabled(false);
			btnAbs.setSoundEffectsEnabled(false);
		}
	}

	public void batchScreen(){

		pref = getSharedPreferences("pref",0);
		
		if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY, "pref_log_pref_font = "+pref.getString("pref_font", "16"));
		
		iSize = Integer.parseInt(pref.getString("pref_font","16"));
		bSound = pref.getBoolean("pref_sound", true);
		bLocation = pref.getBoolean("pref_location", true);
		bVoice = pref.getBoolean("pref_voice", true);

		if(bSound){
			Extend.setSoundEffectsEnabled(true);
			Location.setSoundEffectsEnabled(true);
			Voice.setSoundEffectsEnabled(true);
		}else{
			Extend.setSoundEffectsEnabled(false);
			Location.setSoundEffectsEnabled(false);
			Voice.setSoundEffectsEnabled(false);
		}

		Extend.setOnClickListener(mOnClickListener);
		Voice.setOnClickListener(mOnClickListener);
		Location.setOnClickListener(mOnClickListener);
		input.requestFocus();
		input.setInputType(0);
		input.setTextSize(iSize);
		edit.setTextSize(iSize);

		buttonMatching();
	}

	View.OnClickListener mOnClickListener = new View.OnClickListener() {
		public void onClick(View v) {
			switch(v.getId()){
			case R.id.extend :
				if(bExtend){bExtend = false;}
				else{bExtend = true;}
				batchScreen();
				break;
			case R.id.locate :
				if(bLocation){
					setView();
				}else{
					showDialog(1);
				}
				break;
			case R.id.voice :
				if(bVoice){
					PackageManager pm = getPackageManager();
					List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
							RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
					if (activities.size() != 0) {
						startVoiceRecognitionActivity();
					} else {
						//							startVoiceRecognitionActivity();
						showDialog(3);
					}

				}else{
					showDialog(2);
				}
				break;
			case R.id.equalbtn :
				break;
			default :
				break;
			}
		}
	};
	
	public void setView(){
		startActivity(new Intent(this, MapDialog2.class));
	}

	public void onSaveInstanceState(Bundle outState){
		outState.putBoolean("bExtend", bExtend);
		outState.putString("display", edit.getText().toString());
		outState.putString("input", input.getText().toString());
	}

	public boolean onCreateOptionsMenu(Menu menu){
		super.onCreateOptionsMenu(menu);
		MenuItem item; 
		item = menu.add(0, 1, 0, "설정");
		menu.add(0, 2, 0, "히스토리");
		item.setAlphabeticShortcut('a');

		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item){
		switch(item.getItemId()){
		case 1 :
			if(MyCalcActivity.bLog)Log.v(LogDefine.LOG_MAINACTIVITY, "OptionMenu_Debug_It is 옵션 메뉴 설정");
			Intent setting =  new Intent(this, SettingPreference.class);
			startActivity(setting);
			return true;
		case 2 :
			if(MyCalcActivity.bLog)Log.v(LogDefine.LOG_MAINACTIVITY, "OptionMenu_Debug_It is 옵션 메뉴 히스토리");
			Intent history =  new Intent(this, HistoryList.class);
			startActivity(history);
			return true;
		}
		return false;	
	}

	protected Dialog onCreateDialog(int id){
		switch(id){
		case 1:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("위치")
			.setMessage("위치 서비스를 사용하실 수 없습니다.\n설정메뉴에서 위치 서비스를 설정하세요.")
			.setPositiveButton("닫기", null)
			.create();
		case 2:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("음성")
			.setMessage("음성 서비스를 사용하실 수 없습니다.\n설정메뉴에서 음성 서비스를 설정하세요.")
			.setPositiveButton("닫기", null)
			.create();
		case 3:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("음성사용 불가")
			.setMessage("음성 서비스를 사용하실 수 없습니다.\n")
			.setPositiveButton("닫기", null)
			.create();
		case 4:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("검색 단어 없음")
			.setMessage("검색된 단어가 없습니다.\n다시 검색 하시겠습니까?")
			.setPositiveButton("확인", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					startVoiceRecognitionActivity();			
				}
			})
			.setNegativeButton("닫기", null)
			.create();
		case 5:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("도움말")
			.setSingleChoiceItems(R.array.help, mSelect, new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog, int which) {
					mSelect = which;
					switch(mSelect){
					case 0:
						showDialog(6);
						break;
					case 1:
						showDialog(7);
						break;
					case 2:
						showDialog(8);
						break;
					case 3:
						showDialog(9);
						break;
					case 4:
						showDialog(10);
						break;
					case 5:
						showDialog(11);
						break;
					case 6:
						showDialog(12);
						break;
					case 7:
						showDialog(13);
						break;
					case 8:
						showDialog(14);
						break;
					case 9:
						showDialog(15);
						break;
					case 10:
						showDialog(16);
						break;
					case 11:
						showDialog(17);
						break;
					case 12:
						showDialog(18);
						break;
					default :
						break;
					}
				}
			})
			.setNegativeButton("닫기", null)
			.create();
		case 6:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("덧셈")
			.setMessage("X+Y")
			.setNegativeButton("닫기", null)
			.create();
		case 7:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("뺄셈")
			.setMessage("X-Y")
			.setNegativeButton("닫기", null)
			.create();
		case 8:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("곱셈")
			.setMessage("X*Y")
			.setNegativeButton("닫기", null)
			.create();
		case 9:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("나눗셈")
			.setMessage("X/Y")
			.setNegativeButton("닫기", null)
			.create();
		case 10:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("제곱근")
			.setMessage("sqrt(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 11:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("자승")
			.setMessage("pow(X,Y)")
			.setNegativeButton("닫기", null)
			.create();
		case 12:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("삼각함수")
			.setMessage("tan(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 13:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("삼각함수")
			.setMessage("cos(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 14:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("삼각함수")
			.setMessage("sin(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 15:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("로그")
			.setMessage("log(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 16:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("자연로그")
			.setMessage("ln(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 17:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("계승")
			.setMessage("fac(X)")
			.setNegativeButton("닫기", null)
			.create();
		case 18:
			return new AlertDialog.Builder(MyCalcActivity.this)
			.setTitle("이항계수")
			.setMessage("com(X,Y)")
			.setNegativeButton("닫기", null)
			.create();
		}
		return null;
	}

	private void startVoiceRecognitionActivity() {
		try {
			Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
			intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
					RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
			intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
					"지금 말하세요.");
			startActivityForResult(intent, REQUEST_CODE);
		} catch (ActivityNotFoundException ex) {
			Toast.makeText(this, "Activity Not Found", Toast.LENGTH_LONG).show();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
			final ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
			DialogSet(matches);
		}
		super.onActivityResult(requestCode, resultCode, data);
	}


	public void DialogSet(final ArrayList<String> matches){

		dialog = new Dialog(this);
		dialog.setContentView(R.layout.dialog);
		dialog.setTitle("결과");
		dialog.setCancelable(true);
		list = (ListView)dialog.findViewById(R.id.itemlist);

		ad2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrange(matches));
		list.setAdapter(ad2);

		list.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				String temp = arrange(matches).get(position);
				if(temp.equals("더하기")){
					input.append("+");
				}else if(temp.equals("빼기")){
					input.append("-");
				}else if(temp.equals("곱하기")){
					input.append("*");
				}else if(temp.equals("나누기")){
					input.append("/");
				}else if(temp.equals("루트")){
					input.append("sqrt(");
				}else if(temp.equals("제곱")){
					input.append("pow(");
				}else if(temp.equals("도움말")){
					showDialog(5);
				}else{
					input.append(arrange(matches).get(position));
				}
				dialog.dismiss();
				startVoiceRecognitionActivity();
			}
		});
		Button button = (Button)dialog.findViewById(R.id.confirm);
		button.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		if(!arrange(matches).isEmpty()){
			dialog.show();
		}else{
			showDialog(4);
		}
	}

	private ArrayList<String> arrange(ArrayList<String> content) {
		boolean bCh = false;
		ArrayList<String> arTemp = new ArrayList<String>();
		for(int i = 0; i < content.size(); i++){
			if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY,"Before_ArrayList = "+ content.get(i));
		}
		int i = 0;
		while(i < content.size()){
			String temp = new String();
			temp = content.get(i);
			if(!temp.equals("도움말") && !temp.equals("더하기") && !temp.equals("빼기") && !temp.equals("곱하기") && 
					!temp.equals("나누기") && !temp.equals("제곱") && !temp.equals("루트")){
				for(int j = 0; j < temp.length(); j++){
					if(!Character.isDigit(temp.charAt(j)) || temp.charAt(j) == ' '){
						if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY, "Middle_ArrayList = "+temp.charAt(j));
						bCh = true;
						arTemp.add(content.get(i));
					}
				}
			}
			content.trimToSize();
			i++;
		}
		if(bCh){
			for(int n = 0; n < arTemp.size(); n++ )
				content.remove(arTemp.get(n));
			bCh = false;
		}
		for(int j = 0; j < content.size(); j++){
			if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY,"After_ArrayList = "+ content.get(j));
		}
		return content;
	}

	public static void appendInitData() {
		if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY, "AppendData_result = "+result+"\nlocation = "+location);
		openHelper.insertColumn(result, location);
		//openHelper.close();
	}

	public static void collectionData(String string, boolean aLocation){
		//		result = new String();
		//		location = new String();
		result = string;
		bCheckLoc = aLocation;
		if(bCheckLoc){
			if(MyCalcActivity.bLog)Log.d(LogDefine.LOG_MAINACTIVITY,"location_주소 가져 왔음 = "+location);
		}else{
			location = "위치 정보 저장 안함";			
		}
		appendInitData();
	}

	protected void onDestroy() {
		openHelper.close();
		super.onDestroy();
	}
}